//
//  WWDeliveryMarkView.m
//  Shopping
//
//  Created by 张世敏 on 16/8/20.
//  Copyright © 2016年 张湾湾. All rights reserved.
//

#import "WWDeliveryMarkView.h"

@interface WWDeliveryMarkView()

/** 优惠信息 **/
@property (nonatomic, strong) UILabel *discountInfoLabel;
/** 收货时间(如:闪电送,及时达) **/
@property (nonatomic, strong) UILabel *timeLabel;
/** 收货备注输入框 **/
@property (nonatomic, strong) UITextField *markTextField;

@end

@implementation WWDeliveryMarkView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    
    return self;
}


#pragma mark - 设置界面
-(void)setupUI{
    // "火箭"小图标
    UIImageView *imgView = [[UIImageView alloc] init];
    imgView.backgroundColor = [UIColor lightGrayColor];
    imgView.image = [UIImage imageNamed:@"icon_lighting"];
    imgView.layer.cornerRadius = 5;
    [self addSubview:imgView];
    
    // "闪电超市"
    UILabel *lightingSupermarketLabel = [self addLabelWithColor:[UIColor lightGrayColor] fontSize:13];
    lightingSupermarketLabel.text = @"闪电超市";
    
    // 红色小圆点图片提示
    UIImageView *redImageTip = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"v2_notice_dot"]];
    [self addSubview:redImageTip];
    // 优惠信息
    self.discountInfoLabel = [self addLabelWithColor:[UIColor lightGrayColor] fontSize:12];
    
    // "收货时间"
    UILabel *consigneeTimeLabel = [self addLabelWithColor:[UIColor blackColor] fontSize:15];
    consigneeTimeLabel.text = @"收货时间";
    self.timeLabel = [self addLabelWithColor:[UIColor redColor] fontSize:15];
    
    // "收货备注"
    UILabel *markLabel = [self addLabelWithColor:[UIColor blackColor] fontSize:15];
    markLabel.text = @"收货备注";
    // 收货备注输入框
    self.markTextField = [[UITextField alloc] init];
    [self addSubview:self.markTextField];
    self.markTextField.placeholder = @"  可输入100字以内特殊要求内容";
    self.markTextField.font = [UIFont systemFontOfSize:15];
    self.markTextField.layer.cornerRadius = 5;
    self.markTextField.layer.borderWidth = 1;
    self.markTextField.layer.borderColor = [UIColor lightGrayColor].CGColor;
    
    // "可预订"按钮
    UIButton *reserveBtn = [self addButton];
    [reserveBtn addTarget:self action:@selector(reserveBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    
    // 测试数据
    self.discountInfoLabel.text = @"22:00前满$30免运费,22:00后满$50免运费";
    self.timeLabel.text = @"闪电送,及时达";
    
    // 布局
    [imgView makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(5);
        make.leading.offset(17);
        make.width.equalTo(22);
        make.height.equalTo(22);
    }];
    
    [lightingSupermarketLabel makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(imgView);
        make.leading.equalTo(self).offset(50);
    }];
    
    [redImageTip makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.discountInfoLabel);
        make.leading.equalTo(imgView);
        make.size.equalTo(CGSizeMake(5, 5));
    }];
    
    [self.discountInfoLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lightingSupermarketLabel.bottom).offset(15);
        make.leading.offset(30);
    }];
    
    [consigneeTimeLabel makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.discountInfoLabel.bottom).offset(30);
        make.leading.equalTo(17);
    }];
    
    [self.timeLabel makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(consigneeTimeLabel);
        make.leading.equalTo(consigneeTimeLabel.trailing).offset(10);
    }];
    
    [markLabel makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self).offset(-15);
        make.leading.equalTo(consigneeTimeLabel);
        make.trailing.equalTo(consigneeTimeLabel);
    }];
    
    [self.markTextField makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(markLabel);
        make.leading.equalTo(markLabel.trailing).offset(10);
        make.trailing.equalTo(self).offset(-25);
        make.height.equalTo(30);
    }];
    
    [reserveBtn makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(consigneeTimeLabel);
        make.trailing.offset(-30);
    }];
}


#pragma mark - 点击"可预定"按钮
-(void)reserveBtnClicked:(UIButton *)sender{
    NSLog(@"可预定按钮点击了");
}


/** 添加文字label **/
-(UILabel *)addLabelWithColor:(UIColor *)titleColor fontSize:(CGFloat)fontSize{
    UILabel *label = [[UILabel alloc] init];
    label.textColor = titleColor;
    label.font = [UIFont systemFontOfSize:fontSize];
    [self addSubview:label];
    
    return label;
}


/** 添加按钮 **/
-(UIButton *)addButton{
    UIButton *btn = [[UIButton alloc] init];
    [btn setTitle:@"可预定" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:16];
    [btn addTarget:self action:@selector(reserveBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:btn];
    
    return btn;
}


@end
